package com.gray.blog.typeHandler;

import com.gray.blog.common.util.JsonObjectUtil;
import com.gray.blog.entity.jsonEntity.FrontGeeksExtraInfo;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

/**
 * Created  By zhoux 2020/04/26
 **/
public class FrontGeeksExtraInfoHandler extends BaseTypeHandler<FrontGeeksExtraInfo> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, FrontGeeksExtraInfo parameter, JdbcType jdbcType) throws SQLException {
        System.out.println(i);
        ps.setString(i, JsonObjectUtil.getGson().toJson(parameter));
    }

    @Override
    public FrontGeeksExtraInfo getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return JsonObjectUtil.getGson().fromJson(rs.getString(columnName), FrontGeeksExtraInfo.class);
    }

    @Override
    public FrontGeeksExtraInfo getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return JsonObjectUtil.getGson().fromJson(rs.getString(columnIndex), FrontGeeksExtraInfo.class);
    }

    @Override
    public FrontGeeksExtraInfo getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return JsonObjectUtil.getGson().fromJson(cs.getString(columnIndex), FrontGeeksExtraInfo.class);
    }
}
